#include<bits/stdc++.h>
using namespace std;
typedef long long int
bool st;
int read(int &x){
    x=0;
    char c=0;
    bool f=1;
    while(!isdigit(c)){
        f&=(c!='-');
        c=getchar();
    }
    while(isdigit(c)){
        x=(x<<1)+(x<<3)+(c^48);
        c=getchar();
    }
    x=(f?x:-x);
}
const int N=1e4+5;
int t,n,m,L,V;
//n che shu
//m ce su yi shu
//L zhu gan dao chang du
//V xian su

int d[N],v[N],a[N],p[N],s[N];
//ju li nan duan d[i]
//v[i] de chu su du
//a[i] de jia su du
vector<int>chao[N];
set<int>asdf[N];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    read(t);
    while(t--){
        read(n);
        read(m);
        read(L);
        read(V);
        for(int i=1;i<=n;i++){
            read(d[i]);
            read(v[i]);
            read(a[i]);
        }
        for(int i=1;i<=m;i++){
            read(p[i]);
        }
        /*
        cout<<"s: \n";
        for(int i=1;i<=n;i++){
            for(int j=1;j<=L;j++){
                s[i][j]=sqrt((v[i]*v[i])+2*a[i]*(j-d[i]));
                cout<<s[i][j]<<" ";
            }
            cout<<endl;
                /*
            for(int t=1;t<=(L-d[i])/a[i];t++){
                int res=v[i]*t+0.5*a[i]*(t*t);
                for(int j=)
            }
        }
        */
        //cout<<endl;
        for(int j=1;j<=m;j++){
            for(int i=1;i<=n;i++){
                if(d[i]<=p[j]){
                    if(a[i]==0){
                        //cout<<"i: "<<i<<" j: "<<j<<" d: "<<d[i]<<" v: "<<v[i]<<" a: "<<a[i]<<" p: "<<p[j]<<endl;
                        if(v[i]>V){
                            //cout<<"i: "<<i<<" j: "<<j<<" v: "<<v[i]<<" V: "<<V<<endl;
                            //chao[i].push_back(j);
                            asdf[i].insert(j);
                        }
                    } else if(a[i]!=0){
                        int shun=sqrt((v[i]*v[i])+2*a[i]*(p[j]-d[i]));
                        //cout<<"i: "<<i<<" j: "<<j<<" shun: "<<shun<<endl;
                        //cout<<"i: "<<i<<" j: "<<j<<" d: "<<d[i]<<" v: "<<v[i]<<" a: "<<a[i]<<" p: "<<p[j]<<" shun: "<<shun<<endl;
                        if(shun>V){
                            //cout<<"i: "<<i<<" j: "<<j<<" shun: "<<shun<<" V: "<<V<<endl;
                            //chao[i].push_back(j);
                            asdf[i].insert(j);
                        }
                    }
                    /*
                    else if(a[i]<0){
                        //k shi su du
                        for(int aa=1;aa<=m;aa++){
                            int sp=v[i],lst=0;
                            for(int k=1;k<=L;k++){
                                int res=((k*k)-(v[i]*v[i]))/(2*a[i]);
                                cout<<"i: "<<i<<" j: "<<j<<" aa: "<<aa<<" k: "<<k<<" res: "<<res<<" lst: "<<lst<<" sp: "<<sp<<" V: "<<V<<endl;
                                if(lst+res>p[aa]){
                                    if(sp>V){
                                        //chao[i].push_back(aa);
                                        asdf[i].insert(aa);
                                    }
                                } else if(res==p[aa]){
                                    lst=0;
                                    sp=k;
                                }
                            }
                        }
                        break;
                    }
                    */
                }
            }
        }
        /*
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                //if(a[i]!=0){
                int shun=sqrt((v[j]*v[j])+2*a[j]*(p[i]-d[j]));
                //cout<<"i: "<<i<<" j: "<<j<<" shun: "<<shun<<endl;
                cout<<"d: "<<d[j]<<" v: "<<v[j]<<" a: "<<a[j]<<" p: "<<p[i]<<" shun: "<<shun<<endl;
                if(shun>V){
                    chao[i].push_back(p[j]);
                }
                //}
            }
        }
        */
        set<int>ss;
        multiset<int>asdfasdf[N];
        for(int i=1;i<=n;i++){
            //cout<<"i: "<<i<<endl;
            for(int j:asdf[i]){
                //cout<<j<<":"<<p[j]<<endl;
                chao[i].push_back(j);
                ss.insert(j);
                asdfasdf[i].insert(j);
            }
            //cout<<endl;

        }
        //cout<<endl;
        int ans=0;
        for(int i=1;i<=n;i++){
            ans+=chao[i].size()>=1;
        }
        printf("%lld ",ans);
        /*
        for(int t=0;t<(1<<n);t++){
            if()
        }
        */
        int max1=0;
        for(int t=0;t<(1<<n);t++){
            for(int j=1;j<=n;j++){
                asdfasdf[j].clear();
                for(int k:asdf[j]){
                    asdfasdf[j].insert(k);
                }
            }
            int cc=0;
            for(int i=1;i<=m;i++){
                if(t&(1<<i)){
                    cc++;
                    //cout<<"i: "<<i<<endl;
                    for(int j=1;j<=n;j++){
                        if(asdfasdf[i].find(p[j])!=asdfasdf[i].end()){
                            asdfasdf[i].erase(p[j]);
                        }
                    }
                }
            }
            bool f=1;
            for(int i=1;i<=n;i++){
                if(!(chao[i].size()>1 && asdfasdf[i].size()>1)){
                    f=0;
                    break;
                }
                if(!(chao[i].size()==0 && asdfasdf[i].size()==0)){
                    f=0;
                    break;
                }
            }
            for(int i=1;i<=n;i++){
                 //   cout<<"i: "<<i<<endl;
                //cout<<"chao: \n";
                for(int j:chao[i]){
                  //  cout<<j<<" ";
                }
               // cout<<endl;
               // cout<<"asdfasdf: \n";
                for(int j:asdfasdf[i]){
                 //   cout<<j<<" ";
                }
                //cout<<endl;
            }
            if(f==1){
                max1=max(max1,cc);
        }}
        printf("%lld\n",3);
    }
}
